package com.zhuoyue.system.domain;

import com.zhuoyue.common.core.domain.BaseEntity;

import com.zhuoyue.common.utils.SecurityUtils;
import com.zhuoyue.system.domain.dto.AccountAuthorizeReqDTO;
import com.zhuoyue.system.domain.util.DoUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Date;

/**
 * 账号授权表
 *
 * @author wjming
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TblAccountAuthorize extends BaseEntity {
    /**
     * 主键ID
     */
    private String id;

    /**
     * 组织ID
     */
    private Long deptId;

    /**
     * 组织名称
     */
    private String deptName;

    /**
     * 名称
     */
    private String name;

    /**
     * 地址
     */
    private String address;

    /**
     * 负责人
     */
    private String personInCharge;

    /**
     * 负责人手机号
     */
    private String phone;

    /**
     * 账号
     */
    private String account;

    /**
     * 密码
     */
    private String password;

    /**
     * token信息
     */
    private String token;

    /**
     * token过期时间
     */
    private String tokenExpirationTime;

    /**
     * @param dto
     * @return
     */
    public TblAccountAuthorize addDtoToDo(AccountAuthorizeReqDTO dto) {
        BeanUtils.copyProperties(dto, this);
        setId(DoUtil.uuId());
        setCreateBy(SecurityUtils.getUsername());
        setCreateTime(new Date());
        return this;
    }

    public TblAccountAuthorize updateDtoToDo(AccountAuthorizeReqDTO dto) {
        BeanUtils.copyProperties(dto, this);
        setUpdateBy(SecurityUtils.getUsername());
        setUpdateTime(new Date());
        return this;
    }
}